package ncs.admin.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import ncs.admin.database.CourseDAO;
import ncs.common.model.Course;
import ncs.common.model.RSTableData;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class ActionGetCourse extends ActionSupport {
	private static final long serialVersionUID = -8544741315865539979L;
	private InputStream result;
	private int start;
	private int limit;
	public InputStream getResult() {
		return result;
	}
	public void setResult(InputStream result) {
		this.result = result;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	@Override
	public String execute() throws Exception {
		CourseDAO dao=new CourseDAO();
		List<Course>rs=dao.getCourses(start, limit);
		RSTableData data=new RSTableData();
		data.setData(rs);
		data.setTotalcount(dao.getCourseCount());
		String json=JSON.toJSONString(data);
		result=new ByteArrayInputStream(json.getBytes("UTF-8"));
		return SUCCESS;
	}
}
